<template>
	<view>
		<view class="cu-list menu-avatar">
			<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''" v-for="(item,index) in list"
				:key="index" @touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd"
				:data-target="'move-box-' + index">
				<view class="cu-avatar  lg"></view>
				<view class="content" @click="handleToReceive(item)">
					<view class="text-grey">取件码：{{item.code}}</view>
					<view class="text-gray text-sm">
						{{item.createTime}}
					</view>
				</view>
				<view class="action">
					<view class="cu-tag round bg-grey sm">{{item.acceptCount}}</view>
				</view>
				<view class="move">
					<view class="bg-grey" @click="handleToFiles(item)">管理</view>
					<view class="bg-red" @click="handleDelete(item)">删除</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import store from "@/store"
	import {
		listShare,
		delShare
	} from '@/api/system/share'
	export default {
		data() {
			return {
				modalName: null,
				listTouchStart: 0,
				listTouchDirection: null,
				list: []
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			getList() {
				listShare({
					pageSize: 10,
					pageNum: 1,
					orderByColumn: 'id',
					isAsc: 'desc',
					userId: store.getters.userid
				}).then(res => {
					this.list = res.rows
				})
			},
			handleDelete(item) {
				let that=this
				uni.showModal({
					title: '确认删除',
					content: '你确定要删除这个数据吗？',
					success: function(res) {
						if (res.confirm) {
							delShare(item.id).then(res => {
								that.getList()
							})
						} else if (res.cancel) {
							console.log('用户点击了取消按钮');
						}
					}
				});

			},
			handleToReceive(item) {
				uni.navigateTo({
					url: '/pages/mine/share/receive?shareId=' + item.id
				})
			},
			handleToFiles(item) {
				uni.navigateTo({
					url: '/pages/mine/share/files?shareId=' + item.id
				})
			},
			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			}
		}
	}
</script>

<style>
	.cu-avatar {
		background-image: url('/static/images/suicai.png');
		background-color: initial;
	}
</style>